package com.toubutu.audio.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MailSendUtil {
    @Value("${spring.mail.username:1986805735@qq.com}")
    private String sender;
    @Resource
    private JavaMailSender javaMailSender;

    /**
     * 发送邮件
     * @param email 邮箱
     * @param text 邮件内容
     */
    @Async
    public void sendMessage(String email,String text){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setTo(email);
        simpleMailMessage.setFrom(sender);
        simpleMailMessage.setSubject("邮箱发送短信测试");
        simpleMailMessage.setText("您的验证码为:"+text);
        javaMailSender.send(simpleMailMessage);
    }
}
